﻿using System;
using System.Linq;
using System.Linq.Expressions;
using Tss.MagicWeb.Domain.Abstract;
using Tss.MagicWeb.Domain.Cards;

namespace Tss.MagicWeb.Domain.Concrete
{
    public class BasePhysicalCardRepository : IBasePhysicalCardRepository, IDisposable
    {
        public BasePhysicalCard Read(long id)
        {
            return PhysicalCardCollection.Query().FirstOrDefault(c => c.Id == id);
        }

        public IQueryable<BasePhysicalCard> Query()
        {
            return PhysicalCardCollection.Query();
        }

        public IQueryable<BasePhysicalCard> Query(Expression<Func<BasePhysicalCard, bool>> filter)
        {
            return PhysicalCardCollection.Query().Where(filter);
        }

        public void Create(BasePhysicalCard entity)
        {
            PhysicalCardCollection.Create(entity);
        }

        public void Delete(BasePhysicalCard entity)
        {
            PhysicalCardCollection.Remove(entity);
        }

        public void Update(BasePhysicalCard entity)
        {
            PhysicalCardCollection.Update(entity);
        }

        public BasePhysicalCard GetCardByOracleName(String oracleName)
        {
            return PhysicalCardCollection.Query().FirstOrDefault(c => c.OracleName.Equals(oracleName));
        }

        public BasePhysicalCard GetCardByGuid(Guid guid)
        {
            return PhysicalCardCollection.Query().FirstOrDefault(c => c.PhysicalCardGuid.Equals(guid));
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
    }
}
